package Scene;
import com.badlogic.gdx.physics.box2d.ContactListener; 
import com.badlogic.gdx.physics.box2d.Contact ;
import com.badlogic.gdx.physics.box2d.Manifold;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import GameObj.GameObject;
import scriptmodule.scriptManager;
import scriptmodule.EventDefine;
public class ContactDispatcher implements ContactListener
{
	 // Method descriptor #4 (Lcom/badlogic/gdx/physics/box2d/Contact;)V
	  public void beginContact(Contact arg0)
	  {
  
	  }
	  
	  // Method descriptor #4 (Lcom/badlogic/gdx/physics/box2d/Contact;)V
	  public void endContact(Contact arg0)
	  {
		  
	  }
	  
	  // Method descriptor #7 (Lcom/badlogic/gdx/physics/box2d/Contact;Lcom/badlogic/gdx/physics/box2d/Manifold;)V
	  public void preSolve(Contact arg0, Manifold arg1)
	  {
		  
	  }
	  
	  // Method descriptor #9 (Lcom/badlogic/gdx/physics/box2d/Contact;Lcom/badlogic/gdx/physics/box2d/ContactImpulse;)V
	  public void postSolve(Contact arg0, ContactImpulse arg1)
	  {
		  // ok, get two bodies in collision
		  Fixture fA = arg0.getFixtureA();
		  Fixture fB = arg0.getFixtureB();
		  
		  Body bdA = fA.getBody();
		  Body bdB = fB.getBody();
		  
		  GameObject userdataA = (GameObject)bdA.getUserData();
		  GameObject userdataB = (GameObject)bdB.getUserData();
		  
		  // call script
		  CallScript(arg0, arg1, userdataA, 0);
		  CallScript(arg0, arg1, userdataA, 1);
	  }
	  
	  void CallScript(Contact arg0, ContactImpulse arg1, GameObject gameObj, int idx)
	  {
		  // calculate impuls
		  float normalImpulse = arg1.getNormalImpulses()[idx];
		  
		  scriptManager.CallGameObjScript(gameObj, EventDefine.EVT_OnCollision,
				  gameObj, normalImpulse, arg0);
		  String strInstName = gameObj.GetInstName();
		  
	  }
}
